import 'package:demo/app/modules/home/home_controller.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class VideoRightButtonView extends GetView<HomeController> {
  const VideoRightButtonView({super.key});

  @override
  Widget build(BuildContext context) {
    final state = controller.state;
    return Column(
      children: [
        InkWell(
          onTap: () {},
          child: Column(
            children: [
              Container(
                padding: const EdgeInsets.all(10),
                decoration: const BoxDecoration(
                    color: Colors.white, shape: BoxShape.circle),
                child: Image.asset(
                  "assets/icon_video_to_float_window.webp",
                  scale: 4,
                ),
              ),
              const Text(
                "小窗口",
                style: TextStyle(color: Color(0xff0F72DF), fontSize: 13),
              ),
            ],
          ),
        ),
        const SizedBox(
          height: 10,
        ),
        const _VideoButton(
          title: '邀请',
          assets: "assets/icon_video_guide.webp",
        ),
        const _VideoButton(
          title: '静音',
          assets: 'assets/icon_voice_open.webp',
        ),
        GetBuilder<HomeController>(
          id: 'mute',
          assignId: true,
          builder: (logic) {
            if (state.mute) {
              return _VideoButton(
                title: '静音',
                assets: 'assets/icon_voice_open.webp',
                onTap: () {
                  controller.setMute(true);
                },
              );
            } else {
              return _VideoButton(
                title: '静音',
                assets: 'assets/icon_voice_close.webp',
                onTap: () {
                  controller.setMute(false);
                },
              );
            }
          },
        ),
        InkWell(
          onTap: () {
            controller.switchCamera();
          },
          child: const _VideoButton(
            title: '切换',
            assets: 'assets/icon_change_camera.webp',
          ),
        ),
        InkWell(
          onTap: () {
            controller.toggle();
          },
          child: const _VideoButton(
            title: '挂断',
            assets: 'assets/icon_small_close_video.webp',
          ),
        ),
      ],
    );
  }
}

class _VideoButton extends StatelessWidget {
  final String title;
  final String assets;
  final GestureTapCallback? onTap;
  const _VideoButton(
      {super.key, required this.title, required this.assets, this.onTap});

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.all(5),
      child: InkWell(
        onTap: onTap,
        child: Column(
          children: [
            Container(
              decoration: const BoxDecoration(
                  color: Colors.white, shape: BoxShape.circle),
              child: Image.asset(
                assets,
                scale: 3,
              ),
            ),
            const SizedBox(
              height: 5,
            ),
            Text(
              title,
              style: const TextStyle(color: Color(0xff0F72DF), fontSize: 13),
            )
          ],
        ),
      ),
    );
  }
}
